/*
 * by cansik / Florian
 * Datum: 07.05.2010
 * Zeit: 15:52
 * 
 *
 */
using System;
using System.Data;
using TM.TMObjects;

namespace TM.API
{
	/// <summary>
	/// Contains each function of the API
	/// </summary>
	public class ThatsMe
	{
		Parser.XMLHandler xmlloader;
		
		/// <summary>
		/// Creates a new ThatsMe Object
		/// </summary>
		public ThatsMe()
		{
			//Initialising Objects
			xmlloader = new Parser.XMLHandler();
		}
		
		/// <summary>
		/// Returns a Member Object
		/// </summary>
		/// <param name="nick">The Nickname of the Member</param>
		/// <returns>Member Object</returns>
		public Member getMemberByNick(string nick)
		{
			Member TempMember = new Member();
			DataSet LoadedData = xmlloader.LoadXML("http://thats-me.ch/api/getMemberByNick?nick=" + nick);
			DataTable MemberTable = LoadedData.Tables["member"];
			
			TempMember.ID = Convert.ToInt32(MemberTable.Rows[0]["id"]);
			TempMember.Nick = (String)MemberTable.Rows[0]["nick"];
			TempMember.Birthday = DateTime.Parse((String)MemberTable.Rows[0]["birthday"]);
			TempMember.Sex = (String)MemberTable.Rows[0]["sex"];
			TempMember.Canton = (String)MemberTable.Rows[0]["canton"];
			TempMember.Image = new Uri((String)MemberTable.Rows[0]["image"]);
			TempMember.Profile = new Uri((String)MemberTable.Rows[0]["profile"]);
			
			return TempMember;
		}
		
		public Member getMemberById(int id)
		{
			Member TempMember = new Member();
			DataSet LoadedData = xmlloader.LoadXML("http://thats-me.ch/api/getMemberById?id=" + id.ToString());
			DataTable MemberTable = LoadedData.Tables["member"];
			
			TempMember.ID = Convert.ToInt32(MemberTable.Rows[0]["id"]);
			TempMember.Nick = (String)MemberTable.Rows[0]["nick"];
			TempMember.Birthday = DateTime.Parse((String)MemberTable.Rows[0]["birthday"]);
			TempMember.Sex = (String)MemberTable.Rows[0]["sex"];
			TempMember.Canton = (String)MemberTable.Rows[0]["canton"];
			TempMember.Image = new Uri((String)MemberTable.Rows[0]["image"]);
			TempMember.Profile = new Uri((String)MemberTable.Rows[0]["profile"]);
			
			return TempMember;
		}
	}
}
